home *** CD-ROM | disk | FTP | other *** search
- /* VERSION 0005 (DATE: 28/04/87) (TIME: 22:38) */
- /*
- e (qed) screen editor
-
- (C) G. Nigel Gilbert, MICROLOGY, 1981
-
- August-December 1981
-
- Modified: Aug-Dec 1984: BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
- March 1985: BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
-
- FILE: qed10
-
- FUNCTIONS: fopen,fcreat,fflush,fclose,putc,getc,funlink,
- frename,dskcheck,err1,err2,err3,err4
-
- PURPOSE: file buffer operations extracted and stripped from stdlib1,
- with protection from bdos error crashes added
-
- */
-
- #include "qed.h"
-
- int fopen(filename,iobuf)
- struct iobuffer *iobuf;
- char *filename;
- {
- if ((iobuf -> _fd = open(filename,0))<0)
- return FAIL;
- iobuf -> _nleft = 0;
- return iobuf -> _fd;
- }
-
- int fcreat(name,iobuf)
- char *name;
- struct iobuffer *iobuf;
- {
- if ((iobuf -> _fd = creat(name)) < 0 )
- return FAIL;
- iobuf -> _nextp = iobuf -> _buff;
- iobuf -> _nleft = (NSECTS * SECSIZ);
- return iobuf -> _fd;
- }
-
- int fflush(iobuf) /*does NOT allow more writing*/
- struct iobuffer *iobuf;
- {
- int i;
-
- if (iobuf -> _nleft == (NSECTS * SECSIZ)) return YES;
- i = NSECTS*SECSIZ - iobuf->_nleft;
- if (write(iobuf -> _fd, iobuf -> _buff, i) != i) return FAIL;
- return YES;
- }
-
- int fclose(iobuf)
- struct iobuffer *iobuf;
- {
- return close(iobuf -> _fd);
- }
-
- eputc(c,iobuf) /*stripped down version of standard putc*/
- char c;
- struct iobuffer *iobuf;
- {
- if (iobuf -> _nleft--) return *iobuf -> _nextp++ = c;
- if ((write(iobuf -> _fd, iobuf -> _buff, NSECTS*SECSIZ)) != NSECTS*SECSIZ)
- /*return DFAIL;*/
- return FAIL;
- iobuf -> _nleft = (NSECTS * SECSIZ -1);
- iobuf -> _nextp = iobuf -> _buff;
- return *iobuf -> _nextp++ = c;
- }
-
- int egetc(iobuf) /*the standard getc, trimmed for speed*/
- struct iobuffer *iobuf;
- {
- int nbytes;
-
- if (iobuf -> _nleft--) return *iobuf -> _nextp++;
- if ((nbytes = read(iobuf -> _fd, iobuf -> _buff, NSECTS*SECSIZ))==FAIL) {
- iobuf -> _nleft++;
- return DFAIL;
- }
- iobuf -> _nleft = nbytes - 1;
- iobuf -> _nextp = iobuf -> _buff;
- if (nbytes<(NSECTS*SECSIZ)) {
- (iobuf->_buff)[nbytes]=ENDFILE;
- (iobuf -> _nleft)++;
- }
- return *iobuf->_nextp++;
- }
-
- funlink(name)
- char *name;
- {
- /* if (dskcheck(setjmp(dskerr))) return FAIL;*/
- return unlink(name);
- }
-
- frename(oldname,newname)
- char *oldname,*newname;
- {
- /* if (dskcheck(setjmp(dskerr))) return FAIL;*/
- return rename(oldname,newname);
- }